<template>
  <select-tree-helper
    class="m-filter-treehelp"
    ref="helper"
    :readonly="false"
    :tabIndex="0"
    :hideLabel="true"
    labelPosition="left"
    pageid="filter"
    openIcon="icon-t-arrow-right"
    foldIcon="icon-t-arrow-down"
    customIcon=""
    customIcons=""
    dropDownWidth="500px"
    :historyEnable="FieldActionConfig?.historyEnable"
    :historySaveCount="parseInt(FieldActionConfig?.historySaveCount)"
    :onlyCheckedNotLeaf="FieldActionConfig?.onlyCheckedNotLeaf"
    :responseRelationNode="!!FieldActionConfig?.responseRelationNode"
    :relationIcon="FieldActionConfig?.relationIcon"
    :type="FieldActionConfig?.type + ''"
    :classiFicationCode="FieldActionConfig?.classiFicationCode"
    :classiFicationStepRule="FieldActionConfig?.classiFicationStep"
    :value_pid="FieldActionConfig?.value_pid || 'Name'"
    :lable_pid="FieldActionConfig?.lable_pid || 'Code'"
    :isLeaf="FieldActionConfig?.isLeaf"
    :leafValue="FieldActionConfig?.leafValue"
    :leafValue_custom="FieldActionConfig?.leafValue_custom"
    :isLazy="FieldActionConfig?.isLazy"
    :indent="(FieldActionConfig?.indent || '20') + 'px'"
    :showSequence="FieldActionConfig?.showSequence"
    :displayMapping="FieldActionConfig?.displayMapping"
    :valueMapping="FieldActionConfig?.valueMapping"
    :customResults="FieldActionConfig?.customResults"
    :customResults_result="FieldActionConfig?.customResults_result"
    :showIconField="FieldActionConfig?.showIconField + ''"
    showIconField1=""
    :labelField="FieldActionConfig?.labelField || 'Name'"
    :valueField="FieldActionConfig?.valueField || 'Code'"
    :multiple="FieldActionConfig?.multiple"
    :parentId="FieldActionConfig?.parentId"
    :linker="FieldActionConfig?.link"
    :columns="FieldActionConfig?.columns || []"
    :search="Field?.search || helpDefaultSearch"
    :value="value"
    :text="Filter?.Value"
    @confirm="updateValue"
    @clear="clearValue"
    :placeholder="Filter.placeholder||''"
  ></select-tree-helper>
</template>

<script>
import { useQuasar } from '@teld/q-components';
import selectTreeHelper from 't/bussiness/select-tree-helper';

export default {
  name: 'tree-helper',

  props: ['Filter', 'Field', 'FilterIsClassic', 'modelValue'],

  components: {
    selectTreeHelper,
  },

  emits: ['change'],

  data() {
    return {
      // FieldActionConfig: {
      //   ActionType: 3,
      //   classiFicationCode: 'Code',
      //   classiFicationStep: '2',
      //   columns: [],
      //   customResults: [],
      //   customResults_result: {
      //     dataSource: [
      //       {
      //         description: '',
      //         filter: '',
      //         filterLabel: 'Code',
      //         filterLabelOptions: 'layer2.displayName',
      //         ID: '0444c95d-9520-45be-86a3-c3345afb858a',
      //         Value: 'num1',
      //       },
      //     ],
      //     type: 'default',
      //   },
      //   DataBind: '',
      //   DataSource: '',
      //   dataSource: null,
      //   helperCode: 'filter-tree-test',
      //   historyEnable: true,
      //   historySaveCount: '5',
      //   indent: '20',
      //   isClassiFicationSteps: true,
      //   isLazy: true,
      //   isLeaf: 'a',
      //   JSScript: '',
      //   labelField: 'Name',
      //   lable_pid: 'Code',
      //   leafValue: true,
      //   link: '-',
      //   listDataSource: {
      //     ActionType: 3,
      //     DataBind:
      //       'DataQuery.GetCDO_DO_Area0408BasicList(DefaultInputFilter,PageIndex,PageSize,AdvancedFilter,AdvancedSort).List',
      //     DataSource: '978e508b-ebbc-45e1-9e53-95d60a48dd21',
      //     DataSourceType: 'Action',
      //     DataType: 2,
      //     LoadDataTime: false,
      //     Parameters: [
      //       {
      //         Code: 'DefaultInputFilter',
      //         DataType: 9,
      //         ID: '96c3556f-a509-4644-89e4-23b46bdd6792',
      //         IsEmpty: 0,
      //         Name: '模糊匹配参数',
      //         Value: '',
      //       },
      //       {
      //         Code: 'PageIndex',
      //         DataType: 2,
      //         ID: 'ca2584bb-469c-4e25-b36a-ef116955ca9b',
      //         IsEmpty: 0,
      //         Name: '页码',
      //         Value: '',
      //       },
      //       {
      //         Code: 'PageSize',
      //         DataType: 2,
      //         ID: '72875738-e3c5-407a-a0cc-567aa24d69a5',
      //         IsEmpty: 0,
      //         Name: '分页大小',
      //         Value: '',
      //       },
      //       {
      //         Code: 'AdvancedFilter',
      //         DataType: 9,
      //         ID: '1669927f-46a3-4c79-b252-8b9468245a15',
      //         IsEmpty: 0,
      //         Name: '高级查询过滤条件',
      //         Value: '',
      //       },
      //       {
      //         Code: 'AdvancedSort',
      //         DataType: 9,
      //         ID: 'bb5963a3-997d-42f2-9b3a-6ef7329536c2',
      //         IsEmpty: 0,
      //         Name: '高级查询排序条件',
      //         Value: '',
      //       },
      //     ],
      //     RelatedCdoCode: 'GetCDO_DO_Area0408BasicList',
      //   },
      //   multiple: false,
      //   onlyCheckedNotLeaf: true,
      //   parentId: 'XX',
      //   RelatedCdoCode: '',
      //   relationIcon: '+',
      //   responseRelationNode: 2,
      //   ServicePara: [],
      //   ServiceParam: [],
      //   showIconField: 2,
      //   showSequence: true,
      //   type: 2,
      //   value_pid: 'Code',
      //   valueField: 'Code',
      // },
    };
  },

  computed: {
    FieldActionConfig() {
      let ret = {
        labelField: 'Name',
        valueField: 'Code',
        columns: [],
      };
      const { filter_inputWay, filter_dataValue } = this.Field;
      if (
        filter_inputWay == 'treehelp' &&
        filter_dataValue &&
        typeof filter_dataValue == 'string'
      ) {
        try {
          ret = { ...ret, ...JSON.parse(this.Field.filter_dataValue) };
        } catch (e) {}
      }

      console.log('------------------- tree-helper', ret);
      return ret;
    },

    value() {
      const {
        FieldActionConfig: { multiple },
        Filter,
      } = this;
      return !multiple ? Filter?.ValueName : Filter?.multipleList || [];
    },
  },

  mounted() {
    // this.openHelper();
  },

  methods: {
    helpDefaultSearch: (pageIndex, pageSize, filter) => {
      return new Promise(resolve => {
        resolve({
          ActionID: null,
          ActionCode: null,
          ActionName: null,
          ResultType: 11,
          EntityType: 3,
          DataContent: null,
          Record: {},
          List: [
            {
              ID: '610116',
              Code: '610116',
              Name: '长安区',
              Type: 'A003',
            },
            {
              ID: '610113',
              Code: '610113',
              Name: '雁塔区',
              Type: 'A003',
            },
            {
              ID: '610112',
              Code: '610112',
              Name: '未央区',
              Type: 'A003',
            },
            {
              ID: '610102',
              Code: '610102',
              Name: '新城区',
              Type: 'A003',
            },
            {
              ID: '6101',
              Code: '6101',
              Name: '西安市',
              Type: 'A002',
            },
            {
              ID: '61',
              Code: '61',
              Name: '陕西省',
              Type: 'A001',
            },
            {
              ID: '511112',
              Code: '511112',
              Name: '五通桥区',
              Type: 'A003',
            },
            {
              ID: '5111',
              Code: '5111',
              Name: '乐山市',
              Type: 'A002',
            },
            {
              ID: '510705',
              Code: '510705',
              Name: '安州区',
              Type: 'A003',
            },
            {
              ID: '5107',
              Code: '5107',
              Name: '绵阳市',
              Type: 'A002',
            },
            {
              ID: '510681',
              Code: '510681',
              Name: '广汉市',
              Type: 'A003',
            },
            {
              ID: '5106',
              Code: '5106',
              Name: '德阳市',
              Type: 'A002',
            },
            {
              ID: '510116',
              Code: '510116',
              Name: '双流区',
              Type: 'A003',
            },
            {
              ID: '510112',
              Code: '510112',
              Name: '龙泉驿区',
              Type: 'A003',
            },
            {
              ID: '510107',
              Code: '510107',
              Name: '武侯区',
              Type: 'A003',
            },
            {
              ID: '5101',
              Code: '5101',
              Name: '成都市',
              Type: 'A002',
            },
            {
              ID: '51',
              Code: '51',
              Name: '四川省',
              Type: 'A001',
            },
            {
              ID: '500241',
              Code: '500241',
              Name: '秀山土家族苗族自治县',
              Type: 'A003',
            },
            {
              ID: '500120',
              Code: '500120',
              Name: '璧山区',
              Type: 'A003',
            },
            {
              ID: '500112',
              Code: '500112',
              Name: '渝北区',
              Type: 'A003',
            },
            {
              ID: '500108',
              Code: '500108',
              Name: '南岸区',
              Type: 'A003',
            },
            {
              ID: '500107',
              Code: '500107',
              Name: '九龙坡区',
              Type: 'A003',
            },
            {
              ID: '500103',
              Code: '500103',
              Name: '渝中区',
              Type: 'A003',
            },
            {
              ID: '5001',
              Code: '5001',
              Name: '市辖区',
              Type: 'A002',
            },
            {
              ID: '50',
              Code: '50',
              Name: '重庆市',
              Type: 'A001',
            },
            {
              ID: '460201',
              Code: '460201',
              Name: '市辖区',
              Type: 'A003',
            },
            {
              ID: '460106',
              Code: '460106',
              Name: '龙华区',
              Type: 'A003',
            },
            {
              ID: '460105',
              Code: '460105',
              Name: '秀英区',
              Type: 'A003',
            },
            {
              ID: '4601',
              Code: '4601',
              Name: '海口市',
              Type: 'A002',
            },
            {
              ID: '46',
              Code: '46',
              Name: '海南省',
              Type: 'A001',
            },
            {
              ID: '45',
              Code: '45',
              Name: '广西壮族自治区',
              Type: 'A001',
            },
            {
              ID: '441324',
              Code: '441324',
              Name: '龙门县',
              Type: 'A003',
            },
            {
              ID: '441323',
              Code: '441323',
              Name: '惠东县',
              Type: 'A003',
            },
            {
              ID: '441302',
              Code: '441302',
              Name: '惠城区',
              Type: 'A003',
            },
            {
              ID: '4413',
              Code: '4413',
              Name: '惠州市',
              Type: 'A002',
            },
            {
              ID: '440115',
              Code: '440115',
              Name: '南沙区',
              Type: 'A003',
            },
            {
              ID: '440113',
              Code: '440113',
              Name: '番禺区',
              Type: 'A003',
            },
            {
              ID: '440111',
              Code: '440111',
              Name: '白云区',
              Type: 'A003',
            },
            {
              ID: '4401',
              Code: '4401',
              Name: '广州市',
              Type: 'A002',
            },
            {
              ID: '44',
              Code: '44',
              Name: '广东省',
              Type: 'A001',
            },
            {
              ID: '430121',
              Code: '430121',
              Name: '长沙县',
              Type: 'A003',
            },
            {
              ID: '430112',
              Code: '430112',
              Name: '望城区',
              Type: 'A003',
            },
            {
              ID: '430105',
              Code: '430105',
              Name: '开福区',
              Type: 'A003',
            },
            {
              ID: '430104',
              Code: '430104',
              Name: '岳麓区',
              Type: 'A003',
            },
            {
              ID: '430102',
              Code: '430102',
              Name: '芙蓉区',
              Type: 'A003',
            },
            {
              ID: '4301',
              Code: '4301',
              Name: '长沙市',
              Type: 'A002',
            },
            {
              ID: '43',
              Code: '43',
              Name: '湖南省',
              Type: 'A001',
            },
            {
              ID: '421281',
              Code: '421281',
              Name: '赤壁市',
              Type: 'A003',
            },
            {
              ID: '4212',
              Code: '4212',
              Name: '咸宁市',
              Type: 'A002',
            },
            {
              ID: '421102',
              Code: '421102',
              Name: '黄州区',
              Type: 'A003',
            },
            {
              ID: '4211',
              Code: '4211',
              Name: '黄冈市',
              Type: 'A002',
            },
            {
              ID: '420114',
              Code: '420114',
              Name: '蔡甸区',
              Type: 'A003',
            },
            {
              ID: '420112',
              Code: '420112',
              Name: '东西湖区',
              Type: 'A003',
            },
            {
              ID: '420111',
              Code: '420111',
              Name: '洪山区',
              Type: 'A003',
            },
            {
              ID: '420105',
              Code: '420105',
              Name: '汉阳区',
              Type: 'A003',
            },
            {
              ID: '420104',
              Code: '420104',
              Name: '硚口区',
              Type: 'A003',
            },
            {
              ID: '420103',
              Code: '420103',
              Name: '江汉区',
              Type: 'A003',
            },
            {
              ID: '4201',
              Code: '4201',
              Name: '武汉市',
              Type: 'A002',
            },
            {
              ID: '42',
              Code: '42',
              Name: '湖北省',
              Type: 'A001',
            },
            {
              ID: '411402',
              Code: '411402',
              Name: '梁园区',
              Type: 'A003',
            },
            {
              ID: '4114',
              Code: '4114',
              Name: '商丘市',
              Type: 'A002',
            },
            {
              ID: '410711',
              Code: '410711',
              Name: '牧野区',
              Type: 'A003',
            },
            {
              ID: '410702',
              Code: '410702',
              Name: '红旗区',
              Type: 'A003',
            },
            {
              ID: '4107',
              Code: '4107',
              Name: '新乡市',
              Type: 'A002',
            },
            {
              ID: '410104',
              Code: '410104',
              Name: '管城回族区',
              Type: 'A003',
            },
            {
              ID: '4101',
              Code: '4101',
              Name: '郑州市',
              Type: 'A002',
            },
            {
              ID: '41',
              Code: '41',
              Name: '河南省',
              Type: 'A001',
            },
            {
              ID: '371402',
              Code: '371402',
              Name: '德城区',
              Type: 'A003',
            },
            {
              ID: '3714',
              Code: '3714',
              Name: '德州市',
              Type: 'A002',
            },
            {
              ID: '371328',
              Code: '371328',
              Name: '蒙阴县',
              Type: 'A003',
            },
            {
              ID: '371325',
              Code: '371325',
              Name: '费县',
              Type: 'A003',
            },
            {
              ID: '371312',
              Code: '371312',
              Name: '河东区',
              Type: 'A003',
            },
            {
              ID: '371311',
              Code: '371311',
              Name: '罗庄区',
              Type: 'A003',
            },
            {
              ID: '371302',
              Code: '371302',
              Name: '兰山区',
              Type: 'A003',
            },
            {
              ID: '3713',
              Code: '3713',
              Name: '临沂市',
              Type: 'A002',
            },
            {
              ID: '370613',
              Code: '370613',
              Name: '莱山区',
              Type: 'A003',
            },
            {
              ID: '370281',
              Code: '370281',
              Name: '胶州市',
              Type: 'A003',
            },
            {
              ID: '370214',
              Code: '370214',
              Name: '城阳区',
              Type: 'A003',
            },
            {
              ID: '370213',
              Code: '370213',
              Name: '李沧区',
              Type: 'A003',
            },
            {
              ID: '370212',
              Code: '370212',
              Name: '崂山区',
              Type: 'A003',
            },
            {
              ID: '370211',
              Code: '370211',
              Name: '黄岛区',
              Type: 'A003',
            },
            {
              ID: '37',
              Code: '37',
              Name: '山东省',
              Type: 'A001',
            },
            {
              ID: '350182',
              Code: '350182',
              Name: '长乐区',
              Type: 'A003',
            },
            {
              ID: '350123',
              Code: '350123',
              Name: '罗源县',
              Type: 'A003',
            },
            {
              ID: '350104',
              Code: '350104',
              Name: '仓山区',
              Type: 'A003',
            },
            {
              ID: '350103',
              Code: '350103',
              Name: '台江区',
              Type: 'A003',
            },
            {
              ID: '350102',
              Code: '350102',
              Name: '鼓楼区',
              Type: 'A003',
            },
            {
              ID: '350101',
              Code: '350101',
              Name: '市辖区',
              Type: 'A003',
            },
            {
              ID: '3501',
              Code: '3501',
              Name: '福州市',
              Type: 'A002',
            },
            {
              ID: '35',
              Code: '35',
              Name: '福建省',
              Type: 'A001',
            },
            {
              ID: '340124',
              Code: '340124',
              Name: '庐江县',
              Type: 'A003',
            },
            {
              ID: '340123',
              Code: '340123',
              Name: '肥西县',
              Type: 'A003',
            },
            {
              ID: '340122',
              Code: '340122',
              Name: '肥东县',
              Type: 'A003',
            },
            {
              ID: '340121',
              Code: '340121',
              Name: '长丰县',
              Type: 'A003',
            },
            {
              ID: '340111',
              Code: '340111',
              Name: '包河区',
              Type: 'A003',
            },
            {
              ID: '340104',
              Code: '340104',
              Name: '蜀山区',
              Type: 'A003',
            },
            {
              ID: '340103',
              Code: '340103',
              Name: '庐阳区',
              Type: 'A003',
            },
            {
              ID: '340102',
              Code: '340102',
              Name: '瑶海区',
              Type: 'A003',
            },
            {
              ID: '3401',
              Code: '3401',
              Name: '合肥市',
              Type: 'A002',
            },
            {
              ID: '34',
              Code: '34',
              Name: '安徽省',
              Type: 'A001',
            },
            {
              ID: '321302',
              Code: '321302',
              Name: '宿城区',
              Type: 'A003',
            },
            {
              ID: '3213',
              Code: '3213',
              Name: '宿迁市',
              Type: 'A002',
            },
            {
              ID: '32',
              Code: '32',
              Name: '江苏省',
              Type: 'A001',
            },
            {
              ID: '310113',
              Code: '310113',
              Name: '宝山区',
              Type: 'A003',
            },
            {
              ID: '310112',
              Code: '310112',
              Name: '闵行区',
              Type: 'A003',
            },
            {
              ID: '310104',
              Code: '310104',
              Name: '徐汇区',
              Type: 'A003',
            },
            {
              ID: '3101',
              Code: '3101',
              Name: '市辖区',
              Type: 'A002',
            },
            {
              ID: '31',
              Code: '31',
              Name: '上海市',
              Type: 'A001',
            },
            {
              ID: '130709',
              Code: '130709',
              Name: '崇礼区',
              Type: 'A003',
            },
            {
              ID: '130702',
              Code: '130702',
              Name: '桥东区',
              Type: 'A003',
            },
            {
              ID: '1307',
              Code: '1307',
              Name: '张家口市',
              Type: 'A002',
            },
            {
              ID: '130105',
              Code: '130105',
              Name: '新华区',
              Type: 'A003',
            },
            {
              ID: '130104',
              Code: '130104',
              Name: '桥西区',
              Type: 'A003',
            },
            {
              ID: '1301',
              Code: '1301',
              Name: '石家庄市',
              Type: 'A002',
            },
            {
              ID: '13',
              Code: '13',
              Name: '河北省',
              Type: 'A001',
            },
            {
              ID: '120119',
              Code: '120119',
              Name: '蓟州区',
              Type: 'A003',
            },
            {
              ID: '120117',
              Code: '120117',
              Name: '宁河区',
              Type: 'A003',
            },
            {
              ID: '120116',
              Code: '120116',
              Name: '滨海新区',
              Type: 'A003',
            },
            {
              ID: '120114',
              Code: '120114',
              Name: '武清区',
              Type: 'A003',
            },
            {
              ID: '120113',
              Code: '120113',
              Name: '北辰区',
              Type: 'A003',
            },
            {
              ID: '120112',
              Code: '120112',
              Name: '津南区',
              Type: 'A003',
            },
            {
              ID: '120111',
              Code: '120111',
              Name: '西青区',
              Type: 'A003',
            },
            {
              ID: '120110',
              Code: '120110',
              Name: '东丽区',
              Type: 'A003',
            },
            {
              ID: '120105',
              Code: '120105',
              Name: '河北区',
              Type: 'A003',
            },
            {
              ID: '120104',
              Code: '120104',
              Name: '南开区',
              Type: 'A003',
            },
            {
              ID: '120103',
              Code: '120103',
              Name: '河西区',
              Type: 'A003',
            },
            {
              ID: '120102',
              Code: '120102',
              Name: '河东区',
              Type: 'A003',
            },
            {
              ID: '120101',
              Code: '120101',
              Name: '和平区',
              Type: 'A003',
            },
            {
              ID: '1201',
              Code: '1201',
              Name: '市辖区',
              Type: 'A002',
            },
            {
              ID: '12',
              Code: '12',
              Name: '天津市',
              Type: 'A001',
            },
            {
              ID: '110119',
              Code: '110119',
              Name: '延庆区',
              Type: 'A003',
            },
            {
              ID: '110118',
              Code: '110118',
              Name: '密云区',
              Type: 'A003',
            },
            {
              ID: '110117',
              Code: '110117',
              Name: '平谷区',
              Type: 'A003',
            },
            {
              ID: '110116',
              Code: '110116',
              Name: '怀柔区',
              Type: 'A003',
            },
            {
              ID: '110115',
              Code: '110115',
              Name: '大兴区',
              Type: 'A003',
            },
            {
              ID: '110114',
              Code: '110114',
              Name: '昌平区',
              Type: 'A003',
            },
            {
              ID: '110113',
              Code: '110113',
              Name: '顺义区',
              Type: 'A003',
            },
            {
              ID: '110112',
              Code: '110112',
              Name: '通州区',
              Type: 'A003',
            },
            {
              ID: '110111',
              Code: '110111',
              Name: '房山区',
              Type: 'A003',
            },
            {
              ID: '110109',
              Code: '110109',
              Name: '门头沟区',
              Type: 'A003',
            },
            {
              ID: '110108',
              Code: '110108',
              Name: '海淀区ffff',
              Type: 'A003',
            },
            {
              ID: '110107',
              Code: '110107',
              Name: '石景山区',
              Type: 'A003',
            },
            {
              ID: '110106',
              Code: '110106',
              Name: '丰台区',
              Type: 'A003',
            },
            {
              ID: '110105',
              Code: '110105',
              Name: '朝阳区',
              Type: 'A003',
            },
            {
              ID: '110102',
              Code: '110102',
              Name: '西城区',
              Type: 'A003',
            },
            {
              ID: '110101',
              Code: '110101',
              Name: '东城区',
              Type: 'A003',
            },
            {
              ID: '1101',
              Code: '1101',
              Name: '市辖区',
              Type: 'A002',
            },
            {
              ID: '11',
              Code: '11',
              Name: '北京市',
              Type: 'A001',
            },
          ],
          Schema: {
            ActionID: '978e508b-ebbc-45e1-9e53-95d60a48dd21',
            ActionCode: 'GetCDO_DO_Area0408BasicList',
            ActionName: 'DQ_CDO_地区（分级码）',
            MetadataType: 3,
            ResultType: 11,
            Entity: {
              MetadataID: '978e508b-ebbc-45e1-9e53-95d60a48dd21',
              MetadataCode: 'GetCDO_DO_Area0408BasicList',
              MetadataName: 'DQ_CDO_地区（分级码）',
              Description: null,
              RefSchemaExpr: 'Schema.DQ.GetCDO_DO_Area0408BasicList',
              MetadataType: 3,
              Relation: null,
              ResultType: 11,
              Attributes: [
                {
                  MetadataCode: 'GetCDO_DO_Area0408BasicList',
                  SourceColumnID: null,
                  SourceColumnCode: null,
                  SourceColumnName: null,
                  RefSchemaExpr:
                    'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408',
                  ID: '40ff49f5-7110-479f-8a8c-ce861e5010ab',
                  Code: 'DO_Area0408',
                  Name: '地区（分级码）',
                  Description: null,
                  DataType: 10,
                  OriginDataType: null,
                  IsPrimaryKey: false,
                  SortOrder: 0,
                  IsDetail: false,
                  IsVirtual: false,
                  RelatePropertyCode: null,
                  EntityType: 0,
                  Entity: {
                    MetadataID: '40ff49f5-7110-479f-8a8c-ce861e5010ab',
                    MetadataCode: 'DO_Area0408',
                    MetadataName: '地区（分级码）',
                    Description: null,
                    RefSchemaExpr:
                      'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408',
                    MetadataType: 0,
                    Relation: null,
                    ResultType: 10,
                    Attributes: [
                      {
                        MetadataCode: 'GetCDO_DO_Area0408BasicList',
                        SourceColumnID: '3b431d0f-f3ae-4ab0-9f6f-375f5ff57061',
                        SourceColumnCode: 'ID',
                        SourceColumnName: '主键ID',
                        RefSchemaExpr:
                          'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408.Columns.ID',
                        ID: 'ID',
                        Code: 'ID',
                        Name: '主键ID',
                        Description: null,
                        DataType: 9,
                        OriginDataType: null,
                        IsPrimaryKey: true,
                        SortOrder: 0,
                        IsDetail: true,
                        IsVirtual: false,
                        RelatePropertyCode: null,
                        EntityType: 4,
                        Entity: null,
                        Length: 36,
                        IsRequired: true,
                        Precision: 0,
                        DefaultValue: null,
                        AttributeType: 0,
                        ExtProperties: {
                          IsInternational: false,
                          IsEnableMasking: false,
                          IsEnableColumnPermission: false,
                        },
                      },
                      {
                        MetadataCode: 'GetCDO_DO_Area0408BasicList',
                        SourceColumnID: '42c5c8e1-a36b-4771-a5d7-f2c9756b139f',
                        SourceColumnCode: 'Code',
                        SourceColumnName: '编号',
                        RefSchemaExpr:
                          'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408.Columns.Code',
                        ID: 'Code',
                        Code: 'Code',
                        Name: '编号',
                        Description: null,
                        DataType: 9,
                        OriginDataType: null,
                        IsPrimaryKey: false,
                        SortOrder: 1,
                        IsDetail: true,
                        IsVirtual: false,
                        RelatePropertyCode: null,
                        EntityType: 4,
                        Entity: null,
                        Length: 128,
                        IsRequired: false,
                        Precision: 0,
                        DefaultValue: null,
                        AttributeType: 0,
                        ExtProperties: {
                          IsInternational: false,
                          IsEnableMasking: false,
                          IsEnableColumnPermission: false,
                        },
                      },
                      {
                        MetadataCode: 'GetCDO_DO_Area0408BasicList',
                        SourceColumnID: '731e7fd5-7b5b-4195-98ad-6664f0568381',
                        SourceColumnCode: 'Name',
                        SourceColumnName: '名称',
                        RefSchemaExpr:
                          'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408.Columns.Name',
                        ID: 'Name',
                        Code: 'Name',
                        Name: '名称',
                        Description: null,
                        DataType: 9,
                        OriginDataType: null,
                        IsPrimaryKey: false,
                        SortOrder: 2,
                        IsDetail: true,
                        IsVirtual: false,
                        RelatePropertyCode: null,
                        EntityType: 4,
                        Entity: null,
                        Length: 128,
                        IsRequired: false,
                        Precision: 0,
                        DefaultValue: null,
                        AttributeType: 0,
                        ExtProperties: {
                          IsInternational: false,
                          IsEnableMasking: false,
                          IsEnableColumnPermission: false,
                        },
                      },
                      {
                        MetadataCode: 'GetCDO_DO_Area0408BasicList',
                        SourceColumnID: '6ff85ca4-1de9-4c0b-86c7-b2a9b2cec4b5',
                        SourceColumnCode: 'Type',
                        SourceColumnName: '分类',
                        RefSchemaExpr:
                          'Schema.DQ.GetCDO_DO_Area0408BasicList.Sources.DO_Area0408.Columns.Type',
                        ID: 'Type',
                        Code: 'Type',
                        Name: '分类',
                        Description: null,
                        DataType: 9,
                        OriginDataType: null,
                        IsPrimaryKey: false,
                        SortOrder: 3,
                        IsDetail: true,
                        IsVirtual: false,
                        RelatePropertyCode: null,
                        EntityType: 4,
                        Entity: null,
                        Length: 50,
                        IsRequired: false,
                        Precision: 0,
                        DefaultValue: null,
                        AttributeType: 0,
                        ExtProperties: {
                          IsInternational: false,
                          IsEnableMasking: false,
                          IsEnableColumnPermission: false,
                        },
                      },
                    ],
                    ListTypeMethods: null,
                  },
                  Length: 0,
                  IsRequired: false,
                  Precision: 0,
                  DefaultValue: null,
                  AttributeType: 0,
                  ExtProperties: null,
                },
              ],
              ListTypeMethods: [
                {
                  Code: 'List',
                  ReturnDataType: 11,
                  Description: 'List',
                  IsClientFunc: false,
                  JSFunc: '#GetList',
                  SortOrder: 0,
                  SubMethods: [
                    {
                      Code: 'Current',
                      ReturnDataType: 10,
                      Description: '获取CurrentRowNumber行的记录',
                      IsClientFunc: false,
                      JSFunc: '@EntityGetCDO_DO_Area0408BasicList',
                      SortOrder: 1,
                      SubMethods: null,
                    },
                    {
                      Code: 'CurrentRowNumber',
                      ReturnDataType: 2,
                      Description: '获取当前行号',
                      IsClientFunc: false,
                      JSFunc: '#GetCurrentRowNumber',
                      SortOrder: 2,
                      SubMethods: null,
                    },
                    {
                      Code: 'Rows',
                      ReturnDataType: 2,
                      Description: '获取数据行数',
                      IsClientFunc: false,
                      JSFunc: '#GetRows',
                      SortOrder: 3,
                      SubMethods: null,
                    },
                    {
                      Code: 'Empty',
                      ReturnDataType: 1,
                      Description: '数据是否为空',
                      IsClientFunc: false,
                      JSFunc: '#IsEmpty',
                      SortOrder: 4,
                      SubMethods: null,
                    },
                    {
                      Code: 'Count',
                      ReturnDataType: 2,
                      Description: 'Count',
                      IsClientFunc: false,
                      JSFunc: '#GetCount',
                      SortOrder: 5,
                      SubMethods: null,
                    },
                  ],
                },
              ],
            },
          },
          Count: 148,
        });
      });
    },

    openHelper({ divWidth = 0 }) {
      this.$refs?.helper?.openHelper?.();

      setTimeout(() => {
        const $input = this.$refs?.helper?.$el?.querySelector(
          'input.select_tree_helper_input',
        );

        if ($input) {
          if (divWidth !== 0) {
            const $spans = [
              ...this.$refs?.helper?.$el?.getElementsByClassName(
                'select_tree_helper_result',
              ),
            ];
            const len = $spans.length;
            if (len > 0) {
              $spans.forEach(
                $e => ($e.style.maxWidth = divWidth / 2 / len + 'px'),
              );
              $input.style.maxWidth = divWidth / 2 + 'px';
            } else {
              $input.style.maxWidth = divWidth + 'px';
            }
          }
          $input.focus();
        }
      }, 500);
    },

    updateValue(val) {
      // console.log('=========== updateValue', val);
      const {
        FieldActionConfig: { labelField, valueField, multiple = false },
      } = this;

      let ret;
      if (multiple) {
        ret = val.map(item => ({
          ...item,
          name: item?.[labelField] ?? '',
          code: item?.[valueField] ?? '',
        }));
      } else {
        ret = {
          ...val,
          name: val?.[labelField] ?? '',
          code: val?.[valueField] ?? '',
        };
      }

      this.$emit('change', ret);
    },

    clearValue(val) {
      // console.log('=========== updateValue', val);
      // const {
      //   FieldActionConfig: { labelField, valueField },
      // } = this;
      // this.$emit('change', {
      //   ...val,
      //   name: val?.[labelField] ?? '',
      //   code: val?.[valueField] ?? '',
      // });
    },
  },

  expose: ['openHelper'],
};
</script>

<style lang="scss">
.m-filter-treehelp {
  .select_tree_helper_result {
    display: inline-block;
    // max-width: 50px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    word-wrap: normal;

    > span {
      display: inline-block;
      max-width: 40px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      word-wrap: normal;
    }
  }
}
</style>
